package com.example.onion.hxchat.mvvm;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;

import com.example.onion.hxchat.room.entity.Info;
import com.example.onion.hxchat.room.entity.Message;
import com.example.onion.hxchat.room.repositorywc.MessageRepository;
import com.example.onion.hxchat.room.wcdatabase.MyDataBaseWc;

import java.util.List;

/**
 * @author:onion
 * @data: 2020/7/8
 */
public class MessageViewModel extends AndroidViewModel {

    //将“秒钟”这个字段用MutableLiveData包装起来
    //LiveData是一个抽象类，不能直接使用，所以通常我们使用它的直接子类MutableLiveData。
    private LiveData<List<Message>> messages;

    MessageRepository repository;
    public MessageViewModel(@NonNull Application application, String toUserId,String ownerUserId) {
        super(application);
        repository = new MessageRepository(application,toUserId,ownerUserId);
    }

    public void insertMessage(Message message)
    {
        repository.insertMaster(message);
    }
    public LiveData<List<Message>> getMessages()
    {
        return repository.getMessages();
    }
}
